package com.gasstion.controller;

import com.gasstion.dao.TankDao;
import com.gasstion.dao.TankMainDao;
import com.gasstion.entity.Tank;
import com.gasstion.entity.TankMain;
import com.gasstion.entity.Userinfo;
import com.gasstion.service.TankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/tankMain")
@Scope("prototype")
public class TankMainController {
    @Autowired
    private TankDao tankDao;
    @Autowired
    private TankMainDao tankMainDao;
    @Autowired
    private TankService tankService;

    @RequestMapping("/updateState")
    @ResponseBody
    public List<Tank> updateState(TankMain tankMain,Tank tank){
        tankDao.updateState(tank);
        tankMainDao.save(tankMain);
        return tankDao.queryAll();
    }

    @RequestMapping("/querySearch")
    @ResponseBody
    public Map<String,Object> querySearch(String tankName, int offset, int limit){
        List<TankMain> list = tankService.findAll(tankName,offset,limit) ;
        long count = tankService.findTotalCount(tankName);
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",list) ;
        map.put("total",count) ;
        return  map ;
    }
//    @RequestMapping("/save")
//    @ResponseBody
//    public Map<String,Object> save(int tankId,String detail,int pn,TankMain tankMain){
//        tankMainDao.save1(tankMain);
//        tankDao.update(tankId,detail);
//        List<TankMain> list = tankService.findAll("",(pn-1),2) ;
//        long count = tankService.findTotalCount("");
//        Map<String,Object> map = new HashMap<>() ;
//        map.put("rows",list) ;
//        map.put("total",count) ;
//        return  map ;
//    }
}
